| 964 | } |
| 965 | |
| 966 | private static class AsciiKey<T> extends Key<T> { |
| 967 | private final AsciiMarshaller<T> marshaller; |
| 968 | |
| 969 | /** Keys have a name and an ASCII marshaller used for serialization. */ |
| 970 | private AsciiKey(String name, boolean pseudo, AsciiMarshaller<T> marshaller) { |
| 971 | super(name, pseudo, marshaller); |
| 972 | Preconditions.checkArgument( |
| 973 | !name.endsWith(BINARY_HEADER_SUFFIX), |
| 974 | "ASCII header is named %s. Only binary headers may end with %s", |
| 975 | name, |
| 976 | BINARY_HEADER_SUFFIX); |
| 977 | this.marshaller = Preconditions.checkNotNull(marshaller, "marshaller"); |
| 978 | } |
| 979 | |
| 980 | @Override |
| 981 | byte[] toBytes(T value) { |
| 982 | String encoded = Preconditions.checkNotNull( |
| 983 | marshaller.toAsciiString(value), "null marshaller.toAsciiString()"); |
| 984 | return encoded.getBytes(US_ASCII); |
| 985 | } |
| 986 | |
| 987 | @Override |
| 988 | T parseBytes(byte[] serialized) { |
| 989 | return marshaller.parseAsciiString(new String(serialized, US_ASCII)); |
| 990 | } |
| 991 | } |
| 992 | |
| 993 | private static final class TrustedAsciiKey<T> extends Key<T> { |
| 994 | private final TrustedAsciiMarshaller<T> marshaller; |
nothing calls this directly
no outgoing calls
no test coverage detected