(Object value, MsgpackSchema schema)
| 2740 | // expects. Top-level entry uses schema=null and resolves via the value's |
| 2741 | // "type" field; deeper levels pass an explicit schema for nested values. |
| 2742 | @SuppressWarnings("unchecked") |
| 2743 | private Object applyMsgpackSchema(Object value, MsgpackSchema schema) { |
| 2744 | if (value instanceof Map) { |
| 2745 | Map<String, Object> map = (Map<String, Object>) value; |
| 2746 | // Top-level: look up the schema by the "type" field if applicable. |
| 2747 | if (schema == null) { |
| 2748 | schema = lookupTopLevelSchema(map); |
| 2749 | } |
| 2750 | if (schema != null) { |
| 2751 | java.util.LinkedHashMap<String, Object> ordered = new java.util.LinkedHashMap<>(); |
| 2752 | for (String field : schema.fields) { |
| 2753 | if (map.containsKey(field)) { |
| 2754 | ordered.put(field, applyMsgpackSchema(map.get(field), schema.children.get(field))); |
| 2755 | } |
| 2756 | } |
| 2757 | return ordered; |
| 2758 | } |
| 2759 | // No schema: keep existing iteration order but recurse into values. |
| 2760 | java.util.LinkedHashMap<String, Object> copy = new java.util.LinkedHashMap<>(); |
| 2761 | for (Map.Entry<String, Object> entry : map.entrySet()) { |
| 2762 | copy.put(entry.getKey(), applyMsgpackSchema(entry.getValue(), null)); |
| 2763 | } |
| 2764 | return copy; |
| 2765 | } |
| 2766 | if (value instanceof List) { |
| 2767 | List<Object> list = (List<Object>) value; |
| 2768 | List<Object> copy = new ArrayList<>(); |
| 2769 | for (Object item : list) { |
| 2770 | // List items inherit the parent field's schema. |
| 2771 | copy.add(applyMsgpackSchema(item, schema)); |
| 2772 | } |
| 2773 | return copy; |
| 2774 | } |
| 2775 | return value; |
| 2776 | } |
| 2777 | |
| 2778 | private MsgpackSchema lookupTopLevelSchema(Map<String, Object> map) { |
| 2779 | if (!"hyperliquid".equals(this.id)) return null; |
no test coverage detected