Skip to content

Commit 9dac546

Browse files
authored
Extracting non-decoder changes from the decoder PR (#45546)
* creating class * replacing encoder constants with new class constants * adding fromValue to StructuredMessageFlags * updating module info to contain more packages * style * undoing module info change
1 parent 5a7388d commit 9dac546

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.storage.common.implementation.structuredmessage;
5+
6+
/**
7+
* Constants used in the structured message encoding and decoding process.
8+
*/
9+
public final class StructuredMessageConstants {
10+
/**
11+
* The default version of the structured message.
12+
*/
13+
public static final int DEFAULT_MESSAGE_VERSION = 1;
14+
15+
/**
16+
* The length of the header for version 1 of the structured message.
17+
*/
18+
public static final int V1_HEADER_LENGTH = 13;
19+
20+
/**
21+
* The length of the segment header for version 1 of the structured message.
22+
*/
23+
public static final int V1_SEGMENT_HEADER_LENGTH = 10;
24+
25+
/**
26+
* The length of the CRC64 checksum.
27+
*/
28+
public static final int CRC64_LENGTH = 8;
29+
}

sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/implementation/structuredmessage/StructuredMessageEncoder.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414
import java.util.HashMap;
1515
import java.util.Map;
1616

17+
import static com.azure.storage.common.implementation.structuredmessage.StructuredMessageConstants.CRC64_LENGTH;
18+
import static com.azure.storage.common.implementation.structuredmessage.StructuredMessageConstants.DEFAULT_MESSAGE_VERSION;
19+
import static com.azure.storage.common.implementation.structuredmessage.StructuredMessageConstants.V1_HEADER_LENGTH;
20+
import static com.azure.storage.common.implementation.structuredmessage.StructuredMessageConstants.V1_SEGMENT_HEADER_LENGTH;
21+
1722
/**
1823
* Encoder for structured messages with support for segmenting and CRC64 checksums.
1924
*/
2025
public class StructuredMessageEncoder {
21-
private static final int DEFAULT_MESSAGE_VERSION = 1;
22-
private static final int V1_HEADER_LENGTH = 13;
23-
private static final int V1_SEGMENT_HEADER_LENGTH = 10;
24-
private static final int CRC64_LENGTH = 8;
2526
private static final ClientLogger LOGGER = new ClientLogger(StructuredMessageEncoder.class);
2627

2728
private final int messageVersion;

sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/implementation/structuredmessage/StructuredMessageFlags.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,21 @@ public static StructuredMessageFlags fromString(String value) {
4545
return null;
4646
}
4747

48+
/**
49+
* Parses a serialized value to a StructuredMessageFlags instance.
50+
* @param value the serialized value to parse.
51+
* @return the parsed StructuredMessageFlags object.
52+
* @throws IllegalArgumentException if unable to parse.
53+
*/
54+
public static StructuredMessageFlags fromValue(int value) {
55+
for (StructuredMessageFlags flag : StructuredMessageFlags.values()) {
56+
if (flag.getValue() == value) {
57+
return flag;
58+
}
59+
}
60+
throw new IllegalArgumentException("Invalid value for StructuredMessageFlags: " + value);
61+
}
62+
4863
/**
4964
* Returns the value for a StructuredMessageFlags instance.
5065
*

0 commit comments

Comments
 (0)