0
|
1 //
|
|
2 // MessagePack for Java
|
|
3 //
|
|
4 // Copyright (C) 2009 - 2013 FURUHASHI Sadayuki
|
|
5 //
|
|
6 // Licensed under the Apache License, Version 2.0 (the "License");
|
|
7 // you may not use this file except in compliance with the License.
|
|
8 // You may obtain a copy of the License at
|
|
9 //
|
|
10 // http://www.apache.org/licenses/LICENSE-2.0
|
|
11 //
|
|
12 // Unless required by applicable law or agreed to in writing, software
|
|
13 // distributed under the License is distributed on an "AS IS" BASIS,
|
|
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15 // See the License for the specific language governing permissions and
|
|
16 // limitations under the License.
|
|
17 //
|
|
18 package org.msgpack.unpacker;
|
|
19
|
|
20 import java.math.BigInteger;
|
|
21
|
|
22 final class BigIntegerAccept extends Accept {
|
|
23 BigInteger value;
|
|
24
|
|
25 BigIntegerAccept() {
|
|
26 super("integer");
|
|
27 }
|
|
28
|
|
29 @Override
|
|
30 void acceptInteger(byte v) {
|
|
31 this.value = BigInteger.valueOf((long) v);
|
|
32 }
|
|
33
|
|
34 @Override
|
|
35 void acceptInteger(short v) {
|
|
36 this.value = BigInteger.valueOf((long) v);
|
|
37 }
|
|
38
|
|
39 @Override
|
|
40 void acceptInteger(int v) {
|
|
41 this.value = BigInteger.valueOf((long) v);
|
|
42 }
|
|
43
|
|
44 @Override
|
|
45 void acceptInteger(long v) {
|
|
46 this.value = BigInteger.valueOf(v);
|
|
47 }
|
|
48
|
|
49 @Override
|
|
50 void acceptUnsignedInteger(byte v) {
|
|
51 this.value = BigInteger.valueOf((long) (v & 0xff));
|
|
52 }
|
|
53
|
|
54 @Override
|
|
55 void acceptUnsignedInteger(short v) {
|
|
56 this.value = BigInteger.valueOf((long) (v & 0xffff));
|
|
57 }
|
|
58
|
|
59 @Override
|
|
60 void acceptUnsignedInteger(int v) {
|
|
61 if (v < 0) {
|
|
62 this.value = BigInteger.valueOf((long) (v & 0x7fffffff) + 0x80000000L);
|
|
63 } else {
|
|
64 this.value = BigInteger.valueOf((long) v);
|
|
65 }
|
|
66 }
|
|
67
|
|
68 @Override
|
|
69 void acceptUnsignedInteger(long v) {
|
|
70 if (v < 0L) {
|
|
71 this.value = BigInteger.valueOf(v + Long.MAX_VALUE + 1L).setBit(63);
|
|
72 } else {
|
|
73 this.value = BigInteger.valueOf(v);
|
|
74 }
|
|
75 }
|
|
76 }
|